package com.zhipu.balance.pop

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ActivityUtils
import com.lxj.xpopup.core.CenterPopupView
import com.zhipu.balance.R
import com.zhipu.balance.listener.AddNumberOnClickListener
import com.zhipu.balance.mobile.dao.*
import com.zhipu.balance.mobile.event.*
import com.zhipu.balance.pop.adapter.NumberAdapter

/**
 *
 */
class NumberPopup(var stringDetectionName: String,var uniqueId : String?,var mAddNumberOnClickListener : AddNumberOnClickListener) :  CenterPopupView(ActivityUtils.getTopActivity()),AddNumberOnClickListener{

    override fun getImplLayoutId(): Int {
        return R.layout.popup_numver
    }

    override fun onCreate() {
        super.onCreate()
        var mRecyclerView : RecyclerView = findViewById(R.id.rv)
        mRecyclerView.layoutManager = LinearLayoutManager(context)
        /**
         * 适配器
         */
        var mNumberAdapter = NumberAdapter()
        mNumberAdapter.setStringDetectionName(stringDetectionName)
        mNumberAdapter.setAddNumberOnClickListener(this)
        mRecyclerView.adapter = mNumberAdapter
        when(stringDetectionName){
            "稻谷" ->{
                val mRecordRiceList = RecordRiceDao.getInstance().getUniqueIdList(uniqueId)
                mNumberAdapter.setRecordRice(mRecordRiceList)
            }
            "小麦" ->{
                val mRecordWheatList = RecordWheatDao.getInstance().getUniqueIdList(uniqueId)
                mNumberAdapter.setRecordWheat(mRecordWheatList)
            }
            "玉米" ->{
                val mRecordCornList = RecordCornDao.getInstance().getUniqueIdList(uniqueId)
                mNumberAdapter.setRecordCorn(mRecordCornList)
            }
            "大米" ->{
                val mRecordDaMiList = RecordDaMiDao.getInstance().getUniqueIdList(uniqueId)
                mNumberAdapter.setRecordDaMi(mRecordDaMiList)
            }
            "大豆" ->{
                val mRecordSoybeanList = RecordSoybeanDao.getInstance().getUniqueIdList(uniqueId)
                mNumberAdapter.setRecordSoybean(mRecordSoybeanList)
            }
            "油菜籽" ->{
                val mRecordRapeseedList = RecordRapeseedDao.getInstance().getUniqueIdList(uniqueId)
                mNumberAdapter.setRecordRapeseed(mRecordRapeseedList)
            }
        }
    }

    override fun <T> onSkipClicked(position: Int, item: T) {
        mAddNumberOnClickListener.onSkipClicked(position,item)
        dismiss()
//        when(stringDetectionName){
//            "稻谷" ->{
//                var mRecordRice = item as RecordRice
//            }
//            "小麦" ->{
//                var mRecordWheat = item as RecordWheat
//            }
//            "玉米" ->{
//                var mRecordCorn = item as RecordCorn
//            }
//            "大米" ->{
//                var mRecordDaMi = item as RecordDaMi
//            }
//            "大豆" ->{
//                var mRecordSoybean = item as RecordSoybean
//            }
//            "油菜籽" ->{
//                var mRecordRapeseed = item as RecordRapeseed
//
//            }
//        }
    }
}